<%@page import="com.sinba.common.system.service.ITransactionRecordService"%>
<%@page import="com.sinba.common.business.service.IBuyService"%>
<%@page import="com.sinba.common.business.dto.BuyQueryDTO"%>
<%@page import="com.sinba.common.dto.PageDTO"%>
<%@page import="com.sinba.common.user.dto.AccountDTO"%>
<%@page import="com.sinba.common.business.service.BuyService"%>
<%@page import="com.sinba.common.user.service.IAccountService"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="org.springframework.context.ApplicationContext"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> 
<%@ include file="../language.jsp" %>
<%
if(session.getAttribute("password2")==null){
	/* response.sendRedirect( "login2.jsp?pageUrl=user/buy.jsp");
	return; */
}

ApplicationContext ac = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
IBuyService buyService = (IBuyService)ac.getBean("buyService");
BuyQueryDTO qdto = new BuyQueryDTO();
qdto.setBuyUser((String)session.getAttribute("loginName"));
qdto.setSearchType("BuyAndSell");
int pages = 1;
String sidx = "createTime";
String sord="desc";
if(request.getParameter("pages")!=null && request.getParameter("_pages")!=""){
	pages = Integer.parseInt(request.getParameter("pages"));
}
int rows = 2;
int start = ( pages - 1 ) * rows;
qdto.setStart( start );
qdto.setLimit( rows );
PageDTO pageDTO = buyService.findBuyPage(qdto, sord, sidx);
if(pageDTO!=null){
	pageDTO.setPage( pages );
	pageDTO.setRows( rows );
}
request.setAttribute("pageDTO",pageDTO);

ITransactionRecordService transactionRecordService = (ITransactionRecordService)ac.getBean("transactionRecordService");
Double balance = transactionRecordService.findUserBalance(session.getAttribute("loginName").toString(),"Dynamic");
request.setAttribute("balance",balance);

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title><fmt:message key="i18n.accountZhuanZhang"/>-<fmt:message key="i18n.title"/> </title>
<link rel="shortcut icon" href="../index/favicon.png" />
<link href="../skin/skin1/css/subPage.css" rel="stylesheet">
<link rel="stylesheet" href="css/sub_page_main_style.css" />
</head>
<body style="background:#ede3d1;height:1800px;overflow: auto;">
	<div class="account">
	<div class="top"><fmt:message key="i18n.tradeMg" /> &gt; <fmt:message key="i18n.myBuys" /></div>
	<!-- <div class="left"></div> -->
    <div class="right" style="margin: 0px;">
      <form id="buy_form" action="buy!buy.action" method="post">
	 	<input type="hidden" name="pageUrl" value="buy.jsp" />
	 	<input type="hidden" name="buyDTO.buyUser" value="${session.loginName}" />
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
			<tr>
				<td align="right" width="15%"><fmt:message key="i18n.money"/>:</td>
				<td align="left" width="35%" style="color:red;font-weight: 600">
					<input name="buyDTO.dBuyMoney" id="money" readonly="readonly" type="text" value="${balance} "/>
				</td>
			</tr>
			<tr>
				<td align="right" width="15%"></td>
				<td align="left" width="35%" style="font-weight: 600"><input class="ty_an" type="submit" 
				value="<fmt:message key="i18n.aKeyAutoBuy" />"/></td>
			</tr>
		</table>
	</form>
      <br><br>
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
      	<tr>
      		<td colspan="5" align="center">买入</td>
      		<td colspan="8" align="center">卖出</td>
      	</tr>
        <tr>
        
        	<th scope="col">买入时间</th>
        	<th scope="col">买入金额</th>
        	<th scope="col">买入价位</th>
        	<th scope="col">持有股数</th>
        	<th scope="col">买入状态</th>
        	<th scope="col" style="width: 100px;border-right: none;">波数</th>
        	<th scope="col" style="width: 100px;border-right: none;">卖出股数</th>
        	<th scope="col" style="width: 100px;border-right: none;">卖出价位</th>
        	<th scope="col" style="width: 100px;border-right: none;">已卖出股数</th>
        	<th scope="col" style="width: 100px;border-right: none;">拆分后股数</th>
        	<th scope="col" style="width: 100px;border-right: none;">拆分前股数</th>
        	<th scope="col" style="width: 100px;border-right: none;">拆分倍数</th>
        	<th scope="col" style="width: 100px;">拆分次数</th>
			<%-- <th scope="col"><fmt:message key="i18n.xuhao" /></th> --%>
			<%-- <th scope="col"><fmt:message key="i18n.memberNumber" /></th> --%>
	        <%-- <th scope="col"><fmt:message key="i18n.aid.createData" /></th>
			<th scope="col"><fmt:message key="i18n.aid.money" /></th>
			<th scope="col"><fmt:message key="i18n.matchTime" /></th>
			<th scope="col"><fmt:message key="i18n.status" /></th>
			<th scope="col"><fmt:message key="i18n.remark" /></th> --%>
			<%-- <th scope="col"><fmt:message key="i18n.waitTime" /></th>
			<th scope="col"><fmt:message key="i18n.palyedDay" /></th>
			<th scope="col"><fmt:message key="i18n.dayEarnings" /></th>
			<th scope="col"><fmt:message key="i18n.fhTopDays" /></th>
			<th scope="col"><fmt:message key="i18n.incomeTotal" /></th>
			<th scope="col"><fmt:message key="i18n.operation" /></th> --%>
        </tr>
        <c:if test="${pageDTO.totalSize eq 0}">
			<tr><td colspan="13" align="center"><fmt:message key="i18n.noData"/></td></tr>
		</c:if>
		<c:if test="${pageDTO.totalSize ne 0}">
			<c:forEach items="${pageDTO.data}" var="data">
			<tr>
				<%-- <td>${data.id }</td> --%>
				<%-- <td>${data.buyUser }</td> --%>
				<td><fmt:formatDate value="${data.createTime }" pattern="yyMMdd HH:mm:ss"/></td>
				<td>${data.dBuyMoney }</td>
				<td>${data.buyPrices }</td>
				<td>${data.holdStock }</td>
				<td>
				<c:choose>
				   <c:when test="${data.status eq 1}"> 
					   <span style="color:#008AD4;"><fmt:message key="i18n.tranIng" /></span>
				   </c:when>
				   <c:when test="${data.status eq 2}"> 
					    <span style="color:green;"><fmt:message key="i18n.tranSuccess" /></span>
				   </c:when>
				   <c:when test="${data.status eq 3}"> 
				   		<span style="color:red;"><fmt:message key="i18n.cleaned" /></span>
				   </c:when>
				   <c:otherwise>
					   <span style="color:blue;"><fmt:message key="i18n.Queue" /></span>
				   </c:otherwise>
				</c:choose>
				</td>
				<style>
				.subtd{width: 100px;}
				.subtd_complete{width: 100px;color:green;}
				</style>
				<td colspan="8" style="padding: 0px; margin: 0px;">
					<c:if test="${fn:length(data.sellGrids) ne 0}">
					<table width="100%" >
						<c:forEach items="${data.sellGrids}" var="sellData">
							<tr>
								<td class="subtd <c:if test="${sellData.status eq 2 }">subtd_complete</c:if>">${sellData.remark }</td>
								<td class="subtd <c:if test="${sellData.status eq 2 }">subtd_complete</c:if>">${sellData.sellMoney }</td>
								<td class="subtd <c:if test="${sellData.status eq 2 }">subtd_complete</c:if>">${sellData.sellPrice }</td>
								<td class="subtd <c:if test="${sellData.status eq 2 }">subtd_complete</c:if>">${sellData.sellMoney-sellData.surplusMoney }</td>
								<td class="subtd <c:if test="${sellData.status eq 2 }">subtd_complete</c:if>">${sellData.splitedGuShu }</td>
								<td class="subtd <c:if test="${sellData.status eq 2 }">subtd_complete</c:if>">${sellData.splitedGuShu/2 }</td>
								<td class="subtd <c:if test="${sellData.status eq 2 }">subtd_complete</c:if>">2</td>
								<td class="subtd <c:if test="${sellData.status eq 2 }">subtd_complete</c:if>">${sellData.splitQuy }</td>
							</tr>
						</c:forEach>
					</table>
					</c:if>
				</td>
				
				<%-- <td>
				<c:if test="${data.status ne 3}">${data.queuingDays}</c:if> </td>
				<td>
				<c:if test="${data.status ne 3}">
				<c:if test="${data.queuingDays > 7}">7</c:if><c:if test="${data.queuingDays <= 7}">${data.queuingDays}</c:if>
				</c:if></td>
				<td>
					<c:if test="${data.status ne 3}">2%</c:if>
				</td>
				<td><c:if test="${data.status ne 3}">7</c:if></td>
				<td>
					<c:if test="${data.status ne 3}">
						<c:if test="${data.queuingDays > 7}">${6*data.buyMoney*0.02}</c:if>
						<c:if test="${data.queuingDays <= 7}">${data.queuingDays*data.buyMoney*0.02}</c:if>
					</c:if>
				</td>
				<td>
					<c:if test="${data.status eq 0}">
						<a href="javascript:buyClean('${data.id}')">[<fmt:message key="i18n.cancel" />]</a>
					</c:if>
					<c:if test="${data.status eq 1 or data.status eq 2}">
						<a href="matchBuy.jsp">[<fmt:message key="i18n.detail" />]</a>
					</c:if>
					
				</td> --%>
			</tr>
			</c:forEach>
		</c:if>
      </table>
      	<!-- 分页 start -->
		<div class="page">
		<div class="page_r">
			<ul>
				<li><a href="buy.jsp?pages=1"><fmt:message key="i18n.firstPage"/></a></li>
				<c:if test="${pageDTO.page!=1}">
					<li><a href="buy.jsp?pages=${pageDTO.page-1}"><fmt:message key="i18n.upPage"/></a></li>
				</c:if>
				<li><a>${pageDTO.page}/${pageDTO.total}</a></li>
				<c:if test="${pageDTO.page+1<=pageDTO.total}">
					<li><a href="buy.jsp?pages=${pageDTO.page+1}"><fmt:message key="i18n.nextPage"/></a></li>
				</c:if>
				<li><a href="buy.jsp?pages=${pageDTO.total}"><fmt:message key="i18n.endPage"/></a></li>
				<li><a><fmt:message key="i18n.total"/>${pageDTO.totalSize}<fmt:message key="i18n.tiao"/></a></li>
			</ul>
		</div>
		</div>
		<!-- 分页 end  -->
    </div>
    <!-- 取消提交表单 -->
    <form action="buy!clean.action" method="post" id="buyCleanForm">
    	<input type="hidden" name="pageUrl" value="buy.jsp">
    	<input type="hidden" name="buyDTO.id" id="buyId">
    </form>
    
  </div>
  
<script type="text/javascript" src="../scripts/jquery/jquery-1.4.2.min.js"></script>
<script>
	$(function(){
		$("#buy_form").submit(function(){
			var money = $("#money").val();
			if(isNaN(money)){
				alert('请输入正确的数值！');
			}else{
				/*  var pattern = /^[1-9]\d*000$/; 
				 if(pattern.test(money)){
					 if(parseInt(money)>50000){
						 alert('金额不能超过50000');
					 }else if(parseInt(money)<2000){
						 alert('金额不能少于2000');
					 }else{
						 return true;
					 }
				 }else{
					 alert("请输入1000的倍数");
				 } */
				return true;
			}
			return false;
		});
	});


function findUserNameByLoginName(loginName){
	$.post('registerUser!findUserNameByLoginName.action','registerUserDTO.loginName='+$('#transfer_transAccount').val(),function(res){
		$('#transfer_userName').text(res);
	});	
}

function checkform(){
	if($('#transfer_transAccount').val()==''){
		alert('Into account cannot be empty(转入账号不能为空)!');
		$('#transfer_transAccount').focus();
		return false;
	}
	if($('#transfer_value').val()==''){
		alert('Transferred to the amount can not be empty(转入金额不能为空)!');
		$('#transfer_value').focus();
		return false;
	}
	var toMoeny = $('#transfer_value').val()
	if(toMoeny!=''){
		toMoeny = toMoeny.replace(/(^\s*)|(\s*$)/g, ""); 
	}
	var a = /^(\d*|\-?[1-9]{1}\d*)$/;
	if(!toMoeny.match(a) || toMoeny==0){
		alert("Transferred to the amount of not positive integer(转入金额不是正整数)!");
		return false;
	}
	if(toMoeny % 10 != 0){
		alert('Please enter 10 times the amount(请输入10的倍数金额)!');
		return false;
	}
	if($('#transfer_validCode').val()==''){
		alert('Verification code cannot be empty(验证码不能为空)!');
		$('#transfer_validCode').focus();
		return false;
	}
	if($('#transfer_passwordAnswer').val()==''){
		alert('Secret security answer can not be empty(密保答案不能为空)!');
		$('#transfer_passwordAnswer').focus();
		return false;
	}
	
	$('#transfer_form').submit();
	/**
	$.post('activationCode!authEmailCode.action','dto.type=邮件&dto.category=转账&dto.activationCode='+$('#transfer_validCode').val(),function(res){
		 if(!res){
			 alert('邮箱验证码不正确!');
			 return false;
		 }else{
			 $('#transfer_form').submit();
		 }
	});
	**/
	}

	function buyClean(buyId){
		if(confirm('是否确定要取消，取消后日利息系统会自动扣除?')){
			$('#buyId').val(buyId);
			$('#buyCleanForm').submit();
		}
	}




</script>
</body>
</html>